import Comm from './Comm';

const host={
    main:"http://112.74.74.189/"
}
var urlMap={
    upload:"mock/upload",
    taskList:"youme/task",
    updateTask:"youme/task/{recordId}"
}

function parse(name,data={}){
    var url=urlMap[name];
    const {path={},query={}}=data;
    for(let p in path){
        url=url.replace("{"+p+"}",path[p])
    }
    for(let p in query){
        if(url.indexOf("?")!=-1){
            url+="?"+p+"="+query[p]
        }else{
            url+="&"+p+"="+query[p]
        }
    }
    return host.main+url;
}

export default {
    upload(imagePath){
        var url=parse("upload");
        return Comm.upload({url:url,fileUri:imagePath})
    },
    loadTaskList(){
        var url=parse("taskList");
        return Comm.fetch(url)
    },
    updateTask(recordId,data){
        var url=parse("updateTask",{path:{recordId:recordId}});
        return Comm.post(url,data)
    }
}